<template>
	<scroll-view class="wuc-tab" :class="tabClass" :style="tabStyle" scroll-with-animation scroll-x :scroll-left="scrollLeft">
		<view :class="{ flex: textFlex, 'text-center': textFlex }">
			<view
				class="wuc-tab-item"
				:class="[{ 'flex-sub': textFlex }, index === tabCur ? selectClass + ' cur' : '']"
				v-for="(item, index) in tabList"
				:key="index"
				:id="index"
				@tap="tabSelect(index, $event)"
			>
				<text :class="item.icon"></text>
				<text>{{ item.name }}</text>
			</view>
		</view>
	</scroll-view>
</template>
<script>
export default {
	name: 'wuc-tab',
	data() {
		return {};
	},
	props: {
		tabList: {
			type: Array,
			default() {
				return [];
			}
		},
		tabCur: {
			type: Number,
			default() {
				return 0;
			}
		},
		tabClass: {
			type: String,
			default() {
				return '';
			}
		},
		tabStyle: {
			type: String,
			default() {
				return '';
			}
		},
		textFlex: {
			type: Boolean,
			default() {
				return false;
			}
		},
		selectClass: {
			type: String,
			default() {
				return 'text-blue';
			}
		}
	},
	methods: {
		tabSelect(index, e) {
			if (this.tabCur === index) return false;
			this.$emit('update:tabCur', index);
			this.$emit('change', index);
		}
	},
	computed: {
		scrollLeft() {
			return (this.tabCur - 1) * 60;
		}
	}
};
</script>
<style scoped lang="less">
view,
scroll-view,
swiper {
	box-sizing: border-box;
}
.wuc-tab {
	white-space: nowrap;
	color: rgba(138, 140, 141, 1);
	font-size: 26rpx;
	font-weight: 400;
	background: #ffffff;
}
.wuc-tab-item {
	display: inline-block;
	padding: 24rpx 0 27rpx 0;
}

.tab-selected {
	position: relative;
	color: #66645d;
	&::after {
		content: '';
		position: absolute;
		bottom: 12rpx;
		height: 6rpx;
		width: 40rpx;
		background-color: #66645D;
		border-radius: 6rpx;
		left: 50%;
		transform: translateX(-50%);
	}
}

.wuc-tab.fixed {
	position: fixed;
	width: 100%;
	top: 0;
	z-index: 1024;
	box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.1);
}

.flex {
	display: flex;
}
.text-center {
	text-align: center;
}
.flex-sub {
	flex: 1;
}
.text-blue {
	color: #0081ff;
}
.text-white {
	color: #ffffff;
}
.bg-white {
	background-color: #ffffff;
}
.bg-blue {
	background-color: #0081ff;
}
.text-orange {
	color: #f37b1d;
}

.text-xl {
	font-size: 36rpx;
}
</style>